﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using Lamex.Library;
using DevExpress.Charts.Model;
using DevExpress.XtraCharts;
using Lamex.Interface;
using Lamex.Library.CommonClass;
using Lamex.Common;

namespace Lamex.mMachine.UI
{
    public partial class frmMAC_Equipment_Overview : frmBaseChild
    {
        string sql;
        DataTable dataTable_Type;
        DataTable dataTable_Dept;
        DataTable dataTable_Year;
        DataTable dataTable_State;
        DataTable dataTable_State_NoAccept;
        DataTable dataTable_Inventory;
        DataTable dataTable_Origin;
        DataTable dataTable_Depre;
        DataTable dataTable_Depre_Over;
        string colums_xaxis_Type;
        string colums_yaxis_Type;
        string colums_xaxis_Dept;
        string colums_yaxis_Dept;
        string colums_yaxis_Dept_P;
        string colums_xaxis_Year;
        string colums_yaxis_Year;
        string colums_yaxis_Year_P;
        string colums_xaxis_Origin;
        string colums_yaxis_Origin;
        string colums_yaxis_Origin_P;
        string colums_xaxis_Depre;
        string colums_yaxis_Depre;
        string colums_yaxis_Depre_P;
        string colums_xaxis_Inventory;
        string colums_yaxis_Inventory;
        string colums_yaxis_Inventory_P;
        string colums_xaxis_State;
        string colums_yaxis_State;
        string colums_yaxis_State_P;

        public frmMAC_Equipment_Overview()
        {
            InitializeComponent();
        }

        private void frmMAC_Equipment_Overview_Resize(object sender, EventArgs e)
        {
            splitContainerControl1.SplitterPosition = this.Height / 2;

            splitContainerControl2.SplitterPosition = this.Width / 3;
            splitContainerControl3.SplitterPosition = this.Width / 3;

            splitContainerControl4.SplitterPosition = this.Width / 4;
            splitContainerControl5.SplitterPosition = this.Width / 4;
            splitContainerControl6.SplitterPosition = this.Width / 4;

        }

        private void frmMAC_Equipment_Overview_Load(object sender, EventArgs e)
        {
            try { base.InitButtons(); } catch { }//初始化标准功能，因要应用于RibbonForm，所以加入异常处理
            sbtnRefresh_Click(null, null);
        }

        private void sbtnRefresh_Click(object sender, EventArgs e)
        {
            Common.GetDataTable getData = new Common.GetDataTable();
            //设备类别
            dataTable_Type = new DataTable();
            dataTable_Type = getData.GetMachine_Type();
            colums_xaxis_Type = "设备类别";
            colums_yaxis_Type = "数量";
            Common.ChartControlHelper.setData_Chart(chartControl1, ViewType.Pie, dataTable_Type, colums_xaxis_Type, colums_yaxis_Type);

            //设备分布--柱状图折线图
            dataTable_Dept = new DataTable();
            dataTable_Dept = getData.GetMachine_Dept();
            colums_xaxis_Dept = "设备区域";
            colums_yaxis_Dept = "数量";
            colums_yaxis_Dept_P = "占比";
            Common.ChartControlHelper.setData_Chart_BarLine(chartControl2, dataTable_Dept, colums_xaxis_Dept, colums_yaxis_Dept, colums_yaxis_Dept_P, 2);

            //设备投产时间--柱状图折线图
            dataTable_Year = new DataTable();
            dataTable_Year = getData.GetMachine_Year();
            colums_xaxis_Year = "投产年份";
            colums_yaxis_Year = "数量";
            colums_yaxis_Year_P = "占比";
            Common.ChartControlHelper.setData_Chart_BarLine(chartControl3, dataTable_Year, colums_xaxis_Year, colums_yaxis_Year, colums_yaxis_Year_P, 3);

            //设备状态--柱状图
            dataTable_State = new DataTable();
            dataTable_State_NoAccept = new DataTable();
            dataTable_State = getData.GetREPORT_STATE();
            dataTable_State_NoAccept = getData.GetREPORT_STATE_NoACCEPTANCE();
            colums_xaxis_State = "设备状态";
            colums_yaxis_State = "数量";
            //colums_yaxis_State_P = "占比";
            Common.ChartControlHelper.setData_Chart_Bar(chartControl4, dataTable_State, colums_xaxis_State, colums_yaxis_State, 4);


            //盘点结果--柱状图
            dataTable_Inventory = new DataTable();
            dataTable_Inventory = getData.GetMachine_Inventory();
            colums_xaxis_Inventory = "设备状态";
            colums_yaxis_Inventory = "数量";
           // colums_yaxis_Inventory_P = "占比";
            Common.ChartControlHelper.setData_Chart_Bar(chartControl5, dataTable_Inventory, colums_xaxis_Inventory, colums_yaxis_Inventory, 5);


            //设备产地--柱状图
            dataTable_Origin = new DataTable();
            dataTable_Origin = getData.GetMachine_Origin();
            colums_xaxis_Origin = "设备产地";
            colums_yaxis_Origin = "数量";
           // colums_yaxis_Origin_P = "占比";
            Common.ChartControlHelper.setData_Chart_Bar(chartControl6, dataTable_Origin, colums_xaxis_Origin, colums_yaxis_Origin, 6);

            //设备折旧-饼图
            dataTable_Depre = new DataTable();
            dataTable_Depre = getData.GetMachine_Depre();
            dataTable_Depre_Over = getData.GetMachine_Depre_Over();
            colums_xaxis_Depre = "设备状态";
            colums_yaxis_Depre = "数量";
            //colums_yaxis_Depre_P = "占比";
            Common.ChartControlHelper.setData_Chart(chartControl7, ViewType.Pie, dataTable_Depre, colums_xaxis_Depre, colums_yaxis_Depre);


        }

        public override void DoView(IButtonInfo sender)
        {
            try
            {
                SplashScreenTool.ShowSplashScreen(typeof(WaitForm1));
                sbtnRefresh_Click(null, null);
                base.DoView(sender);
                SplashScreenTool.CloseSplashScreen();
            }
            catch (Exception ex)
            {
                SplashScreenTool.CloseSplashScreen();
            }
       
        }
        public override void DoPrint(IButtonInfo sender)
        {
            Common.ExportHelper exportHelper = new Common.ExportHelper();
            exportHelper.PrintPreview(chartControl1,chartControl2, chartControl3, chartControl4, chartControl5, chartControl6, chartControl7);
            base.DoPrint(sender);
        }

        public override void DoExport(IButtonInfo sender)
        {
            Common.ExportHelper exportHelper = new Common.ExportHelper();
            exportHelper.ExportToExcel(chartControl1, chartControl2, chartControl3, chartControl4, chartControl5, chartControl6, chartControl7);
            base.DoExport(sender);
        }

        #region 双击跳转到设备台帐明细
        //共用一个公共窗体，显示内容及图跟据当前双击项确定

        private void chartControl1_DoubleClick(object sender, EventArgs e)
        {
            frmMAC_Equipment_Detail form = new frmMAC_Equipment_Detail(dataTable_Type, colums_xaxis_Type, colums_yaxis_Type, "", 1);
            // MdiTools.OpenChildForm_Param(this.MdiParent as IMdiForm, form, sender as ToolStripMenuItem);

            MdiTools.OpenChildForm_Param(this.MdiParent as IMdiForm, form, "menuMAC_Account_Overview_Report");

        }
        private void chartControl2_DoubleClick(object sender, EventArgs e)
        {
            frmMAC_Equipment_Detail form = new frmMAC_Equipment_Detail(dataTable_Dept, colums_xaxis_Dept, colums_yaxis_Dept, colums_yaxis_Dept_P, 2);
            // MdiTools.OpenChildForm_Param(this.MdiParent as IMdiForm, form, sender as ToolStripMenuItem);
            MdiTools.OpenChildForm_Param(this.MdiParent as IMdiForm, form, "menuMAC_Account_Overview_Report");
        }

        private void chartControl3_DoubleClick(object sender, EventArgs e)
        {
            frmMAC_Equipment_Detail form = new frmMAC_Equipment_Detail(dataTable_Year, colums_xaxis_Year, colums_yaxis_Year, colums_yaxis_Year_P, 3);
            // MdiTools.OpenChildForm_Param(this.MdiParent as IMdiForm, form, sender as ToolStripMenuItem);
            MdiTools.OpenChildForm_Param(this.MdiParent as IMdiForm, form, "menuMAC_Account_Overview_Report");
        }

        private void chartControl4_DoubleClick(object sender, EventArgs e)
        {
            frmMAC_Equipment_Detail_State form = new frmMAC_Equipment_Detail_State(dataTable_State_NoAccept,dataTable_State, colums_xaxis_State, colums_yaxis_State, 4);
            // MdiTools.OpenChildForm_Param(this.MdiParent as IMdiForm, form, sender as ToolStripMenuItem);
            MdiTools.OpenChildForm_Param(this.MdiParent as IMdiForm, form, "menuMAC_Account_Overview_Report");
        }

        private void chartControl5_DoubleClick(object sender, EventArgs e)
        {
            frmMAC_Equipment_Detail form = new frmMAC_Equipment_Detail(dataTable_Inventory, colums_xaxis_Inventory, colums_yaxis_Inventory, "", 5);
            // MdiTools.OpenChildForm_Param(this.MdiParent as IMdiForm, form, sender as ToolStripMenuItem);
            MdiTools.OpenChildForm_Param(this.MdiParent as IMdiForm, form, "menuMAC_Account_Overview_Report");
        }

        private void chartControl6_DoubleClick(object sender, EventArgs e)
        {
            frmMAC_Equipment_Detail form = new frmMAC_Equipment_Detail(dataTable_Origin, colums_xaxis_Origin, colums_yaxis_Origin, "", 6);
            // MdiTools.OpenChildForm_Param(this.MdiParent as IMdiForm, form, sender as ToolStripMenuItem);
            MdiTools.OpenChildForm_Param(this.MdiParent as IMdiForm, form, "menuMAC_Account_Overview_Report");
        }

        private void chartControl7_DoubleClick(object sender, EventArgs e)
        {
            frmMAC_Equipment_Detail_Depre form = new frmMAC_Equipment_Detail_Depre(dataTable_Depre, dataTable_Depre_Over, colums_xaxis_Depre, colums_yaxis_Depre, colums_yaxis_Depre_P, 7);
            // MdiTools.OpenChildForm_Param(this.MdiParent as IMdiForm, form, sender as ToolStripMenuItem);
            MdiTools.OpenChildForm_Param(this.MdiParent as IMdiForm, form, "menuMAC_Account_Overview_Report");
        }

        #endregion

    }
}